<template>
  <div class="tab-bar-item" @click="routeClick">
    <div v-if="!isActive"><slot name="tab-bar-img"></slot></div>
    <div v-else><slot name="tab-bar-active"></slot></div>
    <div :class="{active: isActive}"><slot name="tab-bar-txt"></slot></div>
  </div>
</template>

<script>
  export default {
    name: "TabBarItem",
    props: {
      path: {
        type: String,
        default: '/home'
      }
    },
    computed: {
      isActive(){
        return this.$route.path.indexOf(this.path) !== -1;
      }
    },
    methods: {
      routeClick(){
        this.$router.push(this.path);
      }
    }
  }
</script>

<style scoped>
  .tab-bar-item{
    flex: 1;
  }
  .active{
    color: var(--color-tint);
  }
</style>